<?php
	include "globals.php";
	$_GET['delete'] = abs((int) $_GET['delete']);
	
	if($_GET['delete']){
		$db->query("DELETE FROM events WHERE evID={$_GET['delete']}

	 AND evUSER=$userid");
	print "<b>Event Deleted</b><br />";
}


if($_GET['delall']){
	print "This will delete all your events.<br>
There is <b>NO</b> undo, so be sure.<br>
> <a href='events.php?delall2=1'>Yes, delete all my events</a><br>
> <a href='events.php'>No, go back</a><br>";
	$h->endpage();
	exit;
}


if($_GET['delall2']){
	$am=$db->num_rows($db->query("SELECT * FROM events WHERE evUSER=$userid"));
	$db->query("DELETE FROM events WHERE evUSER=$userid");
	print "All <b>{$am}

</b> events you had were deleted.<br>
> <a href='events.php'>Back</a><br>";
$h->endpage();
exit;
}

print "<b>Latest 10 events</b><hr />
&gt; <a href='events.php?delall=1'>Delete All Events</a><hr />";
$q=$db->query("SELECT * FROM events WHERE evUSER=$userid ORDER BY evTIME DESC LIMIT 10;");
print "<table width=75% cellspacing=1 class='table'> <tr style='background:gray;'> <th>Time</th> <th>Event</th><th>Links</th> </tr>";
while($r=$db->fetch_row($q)){
	print "<tr><td>".date('F j Y, g:i:s a',$r['evTIME']);
	
	if (!$r['evREAD']){
		print "<br /><b>New!</b>";
	}

	print "</td><td>{$r['evTEXT']}

</td><td><a href='events.php?delete={$r['evID']}

'>Delete</a></td></tr>";
}

print "</table>";

if($ir['new_events'] > 0){
	$db->query("UPDATE events SET evREAD=1 WHERE evUSER=$userid");
	$db->query("UPDATE users SET new_events=0 WHERE userid=$userid");
}

$h->endpage();
?>
